package day1201_3;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class D2 {

    public static void main(String[] args) throws SQLException, ClassNotFoundException {
        saveEmp(1,"zs","电子工程系",4000,300,1500);
    }

    static   void   saveEmp(int id,String name,
                            String dept, double basicSal,
                            double allowance,double bonus) throws SQLException, ClassNotFoundException {
        Connection conn=D1.getConn();//1.获取连接   D1.getConn()
        PreparedStatement st=conn.prepareStatement(
                "insert into emp" +
                        "(id,name,department,basicwages,allowance,bonus) value(?,?,?,?,?,?)");//2.预编译sql
        st.setInt(1,id);//给第一个问号，存入id
        st.setString(2,name);
        st.setString(3,dept);
        st.setDouble(4,basicSal);
        st.setDouble(5,allowance);
        st.setDouble(6,bonus);
        st.executeUpdate();//3.执行SQL    executeUpdate()
        D1.tl.set(conn); //4.关闭连接
    }


}





